/*
 * @Author: wwssaabb
 * @Date: 2021-12-15 15:29:57
 * @LastEditTime: 2021-12-15 15:39:00
 * @FilePath: \handwritten-code\main\trim.js
 */

const test1 = ' asdads asda sd '
const test2 = 'asdads asda sd '
const test3 = ' asdads asda sd'
const test4 = 'asdads asda sd'

//replace+正则匹配
function trim(str) {
  return str.replace(/^\s|\s$/, '')
}


//slice获取取出两边空格的字符串
function trim(str) {
  let len = str.length
  return str.slice(str[0] === ' ' ? 1 : 0, str[len - 1] === ' ' ? -1 : len)
}


console.log(trim(test1))
console.log(trim(test2))
console.log(trim(test3))
console.log(trim(test4))